/**
*      author: Y_Yao
*      created: 2024-12-06 20:30:15
**/

#include<bits/stdc++.h>

#define int LL
using namespace std;
using LL = long long;
const LL LLINF = 1e18;
const int INF = 0x3f3f3f3f;
const int N = 2e5 + 7;
int a[N];
int b[N];
int n;

void solve()
{
    cin >> n;
    int mina = INF,minb = INF;
    for(int i = 1;i <= n;i++)
    {
        cin >> a[i];
        mina = min(mina,a[i]);
    }
    for(int i = 1;i <= n - 1;i++)
    {
        cin >> b[i];
        minb = min(minb,b[i]);
    }
    if(minb < mina)
    {
        cout << -1 << endl;
        return;
    }

    sort(a + 1,a + 1 + n);
    sort(b + 1,b + n);
    int cura = n,curb = n - 1;
    while(b[curb] >= a[cura] && cura != 0 && curb != 0)
    {
        cura--;
        curb--;
    }
    int ans = cura;
    cura--;
    for(int i = cura;i >= 1;i--)
    {
        if(b[i] < a[i])
        {
            cout << -1 << endl;
            return;
        }
    }
    cout << a[ans] << endl;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}